package cn.fsd.controller;

import cn.fsd.domain.*;
import cn.fsd.service.StockInOutService;
import cn.fsd.vo.ResultBean;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/storeroomOP")
public class StockOPController {
    @Autowired
    StockInOutService stockInOutService;

    @RequestMapping(value = "/purchaseIn",method = RequestMethod.POST)
    @ApiOperation("购货入库操作")
    public ResultBean purchaseIn(@RequestBody Purchase_bill purchase_bill){
        stockInOutService.purchaseIn(purchase_bill.getBill_id());
        return ResultBean.success();
    }

    /**
     * 中心库房调拨出库，可以保证出库货物足够，但是目的库房是否超出最大库存量？
     * 直接出库，由目的库房判断是否入库
     */
    @RequestMapping(value = "/transferOut",method = RequestMethod.POST)
    @ApiOperation("调拨出库操作")
    public ResultBean transferOut(@RequestBody Transfer transfer){
        stockInOutService.transferOut(transfer.getTransfer_id());
        return ResultBean.success();
    }

    /**
     * 分站库房调拨入库，入库数量可能会超过最大库存
     * 入库时判断是否超过最大库存，若超过则无法入库
     */
    @RequestMapping(value = "/transferIn",method = RequestMethod.POST)
    @ApiOperation("调拨入库操作")
    public ResultBean transferIn(@RequestBody Transfer transfer){
        stockInOutService.transferIn(transfer.getTransfer_id());
        return ResultBean.success();
    }

    /**
     * 领货
     */
    @RequestMapping(value = "/takeCommodity",method = RequestMethod.POST)
    @ApiOperation("领货操作")
    public ResultBean deliveryOut(@RequestBody Task task){
        stockInOutService.deliveryOut(task.getTask_id());
        return ResultBean.success();
    }

    /**
     * 分站库房退货登记，判断是否超出
     * 依据任务单登记
     */
    @RequestMapping(value = "/exchangeCheckIn",method = RequestMethod.POST)
    @ApiOperation("分站退货登记操作")
    public ResultBean exchangeCheckIn(@RequestBody Task task){
        stockInOutService.exchangeCheckIn(task.getTask_id());
        return ResultBean.success();
    }

    /**
     * 中心库房退货入库，当前库房是否超出最大库存量？
     *依据什么task来退货
     */
    @RequestMapping(value = "/exchangeIn",method = RequestMethod.POST)
    @ApiOperation("中心库房退货入库操作")
    public ResultBean exchangeIn(@RequestBody Task task){
        stockInOutService.exchangeIn(task.getTask_id());
        return ResultBean.success();
    }

    /**
     * 分站库房退货出库，直接出库即可
     */
    @RequestMapping(value = "/exchangeOut",method = RequestMethod.POST)
    @ApiOperation("分站库房退货出库操作")
    public ResultBean exchangeOut(@RequestBody Task task){
        stockInOutService.exchangeOut(task.getTask_id());
        return ResultBean.success();
    }

    /**
     * 中心站退货，直接退货即可
     */
    @RequestMapping(value = "/centerOut",method = RequestMethod.POST)
    @ApiOperation("中心站退货操作")
    public ResultBean centerOut(@RequestBody Task task){
        stockInOutService.centerOut(task.getTask_id());
        return ResultBean.success();
    }




}
